// pages/personlist/person_list.js
var apiHelp = require('../../utils/api.js');
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    person_list:[],
    opendId:""
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    //调用应用实例的方法获取全局数据
    var params = { "opendId": app.globalData.opendId };
    var url = apiHelp.getConect();

    apiHelp.request(url, 'GET', params, function (data, err) {
      that.setData({
        person_list: data
      });
    });
   
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }, tapbutton: function () {
    
    var pages = getCurrentPages();
    var prePage = pages[pages.length - 2];
    var chooseData = [];
    var person_list = this.data.person_list;
    for (var i = 0; i < person_list.length; i++) {
      if(person_list[i]['chooseFlag']){
        chooseData.push(person_list[i]);
      }
    }
    
    prePage.setData({
      person_list: chooseData
    });
   
    wx.navigateBack({
      delta: prePage
    })
     /*
    wx.redirectTo({
       url: '../orderinformation/order_infor'
     })*/
  }, modifyName: function (e) {
    var contactId = e.currentTarget.dataset.contactid;
    wx.navigateTo({
      url: '../modifyperson/mod_person?contactId=' + contactId
    })
  }, addName: function () {
    wx.redirectTo({
      //url: '../addperson/add_person'
      url: '../modifyperson/mod_person'
    })
  },
  choosePassenger:function(e){
    var person_list = this.data.person_list;
    var person_list_temp = [];
    for (var i = 0; i< person_list.length; i++){
      if (person_list[i]['id'] == e.currentTarget.dataset.contractid){
        
        if (person_list[i]['chooseFlag']==false){
          person_list[i]['chooseFlag'] = true;
          person_list[i]['controllerStyle'] = '-5rpx -225rpx';
        }else{
          person_list[i]['chooseFlag'] = false;
          person_list[i]['controllerStyle'] = '-61rpx -226rpx';
        }
           
        person_list_temp.push(person_list[i]);
      }else{
        person_list_temp.push(person_list[i]);
      }
      
    }
    
    this.setData({
      person_list: person_list_temp
    });
  }
})